<template>
  <!-- 运行历史 -->
  <BaseMainSlot :show-tab="true">
    <template v-slot:btn-box>
      <ActionBar
        :add-active="addActive"
        :del-active="delActive"
        :edit-active="editActive"
        :cancel-active="cancelActive"
        :save-active="saveActive"
        :has-add="false"
        :has-edit="false"
        :has-save="false"
        :has-del="false"
      />
    </template>
    <template v-slot:search-box>
      <SearchBox @search="search">
        <div class="common-search-item">
          <div class="label">流程名称:</div>
          <div class="input">
            <el-input v-model="searchForm.name" clearable @keyup.enter.native="search" @blur="search"  @clear="search" />
          </div>
        </div>
        <div class="common-search-item">
          <div class="label">业务号:</div>
          <div class="input">
            <el-input v-model="searchForm.bussinesskey" clearable @keyup.enter.native="search" @blur="search"  @clear="search" />
          </div>
          <!-- <div class="label"><span style="font-size: 20px">当前基地：{{ organizationName }}</span></div> -->
        </div>
      </SearchBox>
    </template>
    <template v-slot:table-box>
      <!-- 业务组件展示表格 -->
      <div class="zh-table-view">
        <el-table
          :data="tableData"
          height="100%"
        >
          <el-table-column
            type="index"
            width="50"
          />
          <el-table-column
            prop="processInstanceId"
            label="流程实例编号"
          />
          <el-table-column
            prop="bussinesskey"
            label="业务号"
          />
          <el-table-column
            prop="name"
            label="流程名称"
          />
          <el-table-column
            prop="currentTask"
            label="当前节点"
          />
          <el-table-column
            prop="assignee"
            label="当前处理人"
          />
          <el-table-column
            prop="ended"
            label="是否结束"
          >
            <template slot-scope="scope">
              {{ scope.row.ended == true ? '是' : '否' }}
            </template>
          </el-table-column>
          <el-table-column
            prop="startTime"
            label="开始时间"
          />
          <el-table-column
            prop="endTime"
            label="结束时间"
          />
          <el-table-column
            prop="startUserId"
            label="发起人"
          />
          <el-table-column label="操作" width="200">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="warning"
                @click="showHistory(scope.row)"
              >查看历史</el-button>
              <el-button
                size="mini"
                type="primary"
                @click="showVariable(scope.row)"
              >查看变量</el-button>
            </template>
          </el-table-column>
        </el-table>
        <Pagination
          :page-size="pageSize"
          :current-page="currentPage"
          :total-size="totalSize"
          @changePageSize="changePageSize"
          @changeCurrentPage="changeCurrentPage"
        />
      </div>
    </template>
    <template v-slot:dialog>
      <el-dialog
        :title="tableDetail == 1 ? '执行记录' : '流程变量'"
        class="formData"
        :visible.sync="dialogFormVisible"
        width="50%"
        top="5vh"
        :before-close="() => {dialogFormVisible = false}"
      >
        <el-table
          class="detailTable"
          stripe
          :data="tableDetailData"
          height="400px"
        >
          <el-table-column
            type="index"
            width="50"
          />
          <el-table-column
            v-for="item,index in tableColumn"
            :key="index"
            :prop="item.prop"
            :label="item.label"
          />
        </el-table>
        <div class="tablePage">
          <Pagination
            :page-size="pageSize2"
            :current-page="currentPage2"
            :total-size="totalSize2"
            @changePageSize="changePageSize2"
            @changeCurrentPage="changeCurrentPage"
          />
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancel()">取 消</el-button>
          <el-button type="primary" @click="cancel()">确 定</el-button>
        </div>
      </el-dialog>
    </template>
  </BaseMainSlot>
</template>
<script>
import ActionBar from "@/components/ActionBar/index";
import { mymixin } from "@/utils/mixins";
import SearchBox from "@/components/SearchBox";
import BaseMainSlot from "@/components/BaseMainSlot/newBaseMainSlot.vue";
import zhreq from "@/api/base-manage/base-user-manage";
import axios from "axios";
import Pagination from "@/components/Pagination";
import baseURL from '@/api/baseURL'
export default {
  components: { ActionBar, BaseMainSlot, Pagination, SearchBox },
  mixins: [mymixin],
  data() {
    return {
      tableData: [],
      pageSize: 10,
      currentPage: 1,
      totalSize: 0,
      // 历史数据
      pageSize2: 10,
      currentPage2: 1,
      totalSize2: 0,
      // ---添加相关---
      formData: {},
      databaseName: 'DB_TDW1_TENANT',
      searchForm: {
        pageId: '', pageTitle: '',
      },
      rules: {
        key: [{ required: true, message: "请输入模型标识", trigger: "blur" }],
        name: [{ required: true, message: "请输入模型名字", trigger: "blur" }],
      },
      tableDetail: 1,
      tableColumn: [],
      tableDetailData: [],
      tableColumn1: [
        { prop: 'processInstanceId', label: '流程实例编号' },
        { prop: 'taskName', label: '活动名称' },
        { prop: 'assignee', label: '办理人' },
        { prop: 'comment', label: '审批意见' },
        { prop: 'startTime', label: '开始时间' },
        { prop: 'endTime', label: '结束时间' },
      ],
      tableColumn2: [
        { prop: 'variableName', label: '变量名' },
        { prop: 'variableTypeName', label: '变量类型' },
        { prop: 'value', label: '变量值' },
        { prop: 'createTime', label: '创建时间' },
        { prop: 'lastUpdatedTime', label: '最后修改时间' },
      ]
    };
  },
  mounted() {
    this.gettabledataList()
  },
  methods: {
    // 操作栏
    async showHistory(row) {
      this.tableDetail = 1
      this.tableRow = row
      this.tableColumn = this.tableColumn1
      this.dialogFormVisible = true

      let dataForm = new FormData()
      dataForm.append('pageNum', this.currentPage2)
      dataForm.append('pageSize', this.pageSize2)
      const { data: mes } = await axios({
        method: "post",
        url: baseURL.socialServiceUrl + '/service/flow/monitor/history/'+row.processInstanceId,
        headers: {
          databaseName: this.databaseName
        },
        data: dataForm
      })
      if (mes.code === 200) {
        this.tableDetailData = mes.data.rows || []
        this.totalSize2 = mes.data.total
      } else {
        this.tableDetailData = []
        this.$message.warning("获取历史数据失败")
      }
    },
    async showVariable(row) {
      this.tableDetail = 2
      this.tableRow = row
      this.tableColumn = this.tableColumn2
      this.dialogFormVisible = true

      let dataForm = new FormData()
      dataForm.append('pageNum', this.currentPage2)
      dataForm.append('pageSize', this.pageSize2)
      const { data: mes } = await axios({
        method: "post",
        url: baseURL.socialServiceUrl + '/service/flow/monitor/variables/'+row.processInstanceId,
        headers: {
          databaseName: this.databaseName
        },
        data: dataForm
      })
      if (mes.code === 200) {
        this.tableDetailData = mes.data.rows || []
        this.totalSize2 = mes.data.total
      } else {
        this.tableDetailData = []
        this.$message.warning("获取历史数据失败")
      }
    },
    // 获取表格信息
    async gettabledataList() {
      let dataForm = new FormData()
      dataForm.append('pageNum', this.currentPage)
      dataForm.append('pageSize', this.pageSize)
      dataForm.append('bussinesskey', this.searchForm.bussinesskey || '')
      dataForm.append('name', this.searchForm.name || '')
      const { data: mes } = await axios({
        method: "post",
        url: baseURL.socialServiceUrl + '/service/flow/monitor/listHistoryProcess',
        headers: {
          databaseName: this.databaseName
        },
        data: dataForm
      })
      // console.log(mes)
      if (mes.code === 200) {
        this.tableData = mes.data.rows || []
        this.totalSize = mes.data.total
        this.resetActionBar()
      } else {
        this.$message.warning("获取表格失败")
      }
    },
    handleSelectionChange() {
      this.nowselectedList = [];
      const list = this.$refs.catetreetwo.getCheckedNodes();
      this.nowselectedList = list.map((item) => {
        return item.id;
      });
      if (this.nowselectedList && this.nowselectedList.length > 0) {
        this.delActive = true;
      } else this.delActive = false;
    },
    // 搜索
    search() {
      this.currentPage = 1;
      this.gettabledataList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.gettabledataList();
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.gettabledataList();
    },
    changePageSize2(pageSize) {
      this.pageSize2 = pageSize;
      this.tabelSearch();
    },
    changeCurrentPage(currentPage) {
      this.currentPage2 = currentPage;
      this.tabelSearch();
    },
    tabelSearch() {
      if (this.tableDetail == 1) {
        this.showHistory(this.tableRow)
      } else {
        this.showVariable(this.tableRow)
      }
    },
  }
};
</script>

<style lang="scss" scoped>
  @import "~@/styles/variables.scss";

  .business-main{
  width: 100%;
  height: 100%;
  .topbar-view{
    width: 100%;
    margin-bottom: 5px;
  }
  .zh-table-view{
    width: 100%;
    height: calc(100% - 60px);
    position: relative;
  }
}
.add-components-dia {
  width: 502px;
  // height: 191px;
  background: #303640;
  border: 1px solid #005c6f;
  border-radius: 7px;
  position: fixed;
  top: 15%;
  left: 40%;
  // background-color: #005c6f;
  z-index: 99;
  .top-bar {
    width: 502px;
    height: 10px;
    background: linear-gradient(90deg, #3581fb 0%, #00faad 100%);
    border-radius: 7px 7px 0px 0px;
  }
  .top-title-line {
    width: 490px;
    height: 35px;
    line-height: 35px;
    padding: 6px 8px;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #484a4e;
    .line-title {
      height: 20px;
      font-size: 14px;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: $textColor;
      letter-spacing: 2px;
    }
    .line-close {
      color: #10d7c4;
      cursor: pointer;
    }
    .line-close:hover {
      color: $textColor;
    }
  }
  .screen-dia-main {
    width: 502px;
    padding: 20px 10px;
    // max-height: 550px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 480px;
    .title-config{
      padding-bottom: 20px;
      border-bottom: #00faad 1px solid;
      margin-bottom: 10px;
    }
    .dia-main-inputline {
      width: 482px;
      margin-top: 5px;
      display: flex;
      // justify-content: center;
      align-items: center;
      margin-bottom: 10px;
      .inputline-name {
        width: 120px;
        height: 24px;
        font-size: 16px;
        font-family: PingFang SC-Regular, PingFang SC;
        font-weight: 400;
        color: $textColor;
        line-height: 24px;
        text-align: center;
      }
      .inputline-value {
        width: 350px;
        height: 32px;
        box-sizing: border-box;
        border-radius: 0px 0px 0px 0px;
        opacity: 1;
        border: 1px solid #494e57;
        box-sizing: border-box;
        outline: 0;
      }
      .textarealine-value {
        width: 350px;
        height: 32px;
        box-sizing: border-box;
        border-radius: 0px 0px 0px 0px;
        opacity: 1;
        border: 1px solid #494e57;
        box-sizing: border-box;
        outline: 0;
      }
      .icon-line-value {
        width: 48px;
        height: 48px;
        text-align: center;
        .not-iconurl {
          border: 1px dashed #d9d9d9;
          border-radius: 6px;
          cursor: pointer;
          position: relative;
          overflow: hidden;
        }
        .not-iconurl:hover {
          border-color: #1caf7e;
        }
        .not-iconsty {
          font-size: 20px;
          color: #8c939d;
          width: 48px;
          height: 48px;
          line-height: 48px;
          text-align: center;
        }
      }
      .selcect-one {
        width: 350px;
        height: 32px;
        box-sizing: border-box;
        border-radius: 0px 0px 0px 0px;
        opacity: 1;
        border: 1px solid #494e57;
        box-sizing: border-box;
        outline: 0;
      }
    }
    .dia-main-addline {
      width: 442px;
      font-size: 16px;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: $textColor;
      line-height: 24px;
      border-bottom: #00faad 1px dashed;
      padding-bottom: 16px;
      margin-bottom: 10px;
      .components-line {
        display: flex;
        // justify-content: space-between;
        align-items: center;
        width: 442px;
        height: 48px;
        .slect-name {
          width: 90px;
          height: 36px;
          font-size: 16px;
          font-family: PingFang SC-Regular, PingFang SC;
          font-weight: 400;
          color: $textColor;
          line-height: 36px;
          text-align: center;
        }
        .selcect-one {
          width: 350px;
          color: #00faad;
          margin-top: 12px;
          height: 36px;
          line-height: 36px;
          background-color: transparent;
          border: #00faad dashed 1px;
          cursor: pointer;
          option {
            background-color: #005c6f !important;
            color: $textColor;
            cursor: pointer;
          }
        }
      }
      .addline-but {
        width: 442px;
        display: flex;
        justify-content: space-around;
        margin-top: 15px;
        .addline-but1 {
          color: #00faad;
          border: 1px solid #00faad;
          cursor: pointer;
          padding: 5px 10px;
        }
        .addline-but1:hover {
          color: $textColor;
        }
        .addline-but2 {
          color: #3581fb;
          border: 1px solid #3581fb;
          cursor: pointer;
          padding: 5px 10px;
        }
        .addline-but2:hover {
          color: $textColor;
        }
      }
    }
    .dia-main-addline:last-of-type {
      padding-bottom: 0;
      margin: 0;
      border: none;
    }
    .showkuang-one {
      position: relative;
      left: 41px;
      width: 400px;
      min-height: 200px;
      .kuangone-main {
        position: absolute;
        width: 100%;
        height: 400px;
      }
    }
  }
  .bottom-bar {
    width: 482px;
    height: 50px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-size: 16px;
    .bottom-bar-cancel {
      width: 96px;
      height: 33px;
      border-radius: 5px 5px 5px 5px;
      border: 1px solid #0cb9ae;
      color: #0cb9ae;
      cursor: pointer;
      line-height: 33px;
      text-align: center;
    }
    .bottom-bar-cancel:hover {
      color: #00faad;
    }
    .bottom-bar-confirm {
      width: 96px;
      height: 33px;
      background: #0cb9ae;
      border-radius: 5px 5px 5px 5px;
      cursor: pointer;
      line-height: 33px;
      text-align: center;
    }
    .bottom-bar-confirm:hover {
      color: #10fab4;
    }
  }
}
::v-deep .detailTable {
  td,
  .el-table__empty-text {
    color: #000 !important;
  }
  .el-table__row--striped {
    background: transparent ;
  }
}

::v-deep .tablePage {
  width: 100%;
  height: 36px;
  margin-top: 10px;
  position: relative;
  bottom: auto;
  top: 10px;
  .el-pagination__jump,
  .el-pagination__total {
    color: #000 !important;
  }
}
</style>
